let express = require('express');
let router = express.Router();
let shoppingAndStarDao = require("../dao/ShoppingAndStarDao");
let pager = require("../util/PagerHelper")

/* GET users listing. */
router.all('/list.do', function(req, res, next) {
    pager.href ="/api/star/list.do";
    let table = "star",
        where = "",
        and = ""
   shoppingAndStarDao.findBy(table,where,and).then(data => {
      pager.data = data;
    res.json({
      code:200, //结果编码,200表示成功，404表示未找到
      data:pager
    });
  }).catch(err => next(err));
});
/*
根据id删除一条数据
 */
router.get("/del.do",((req,res,next) =>{
    let table = "star"
    if(req.query.id){
        console.log(req.query.id)
        shoppingAndStarDao.deleteById(table, req.query.id).then(data => {
            res.json({
                code:200,
                msg: "删除成功"
            })
        }).catch(err => next(err));
    } else {
        res.json({
            code:404,
            msg: "没有传id值"
        })
    }
}));


module.exports = router;
